<?php
namespace app\admin\controller;

use think\Controller;
use expand\Auth;
use app\admin\model\Config;
/**
 * admin基础控制器
 * @author duqiu
 */
class Common extends Controller
{
    /**
     * 基础控制器初始化
     * @author duqiu
     */
    public function initialize()
    {
        $userId = session('userId');
        if(!$userId){//将请求的链接发送到一次性session中
            $this->redirect('/admin/login/index');
        }
        define('UID', $userId);//设置登陆用户ID常量
        define('MODULE_NAME', request()->module());
        define('CONTROLLER_NAME', request()->controller());
        define('ACTION_NAME', request()->action());

        $auth = new Auth();
        if (!$auth->check(CONTROLLER_NAME.'/'.ACTION_NAME, UID)){
            if(request()->isAjax()){
                $data=['code' => 404, 'msg' => '当前没有权限，请联系管理员获取权限！', 'data' => null];
                echo json_encode($data);exit;
            }else{
                $this->redirect('/403.html');
            }
        }

    }

}